package tree;

import java.util.ArrayList;
import java.util.Collection;

public class Node {
	
	private Node parent;
	
	private Collection<Node> children;
	
	private int value;
	
	private boolean visited;
	
	// Constructor(s)
	public Node(Node parent) {
		this.parent = parent;
		this.children = new ArrayList<Node>();
		this.value = 1;
		this.visited = false;
	}
	
	public Node(Node parent, int value) {
		this.parent = parent;
		this.children = new ArrayList<Node>();
		this.value = value;
		this.visited = false;
	}
	
	/*
	 * TODO: See if this can be done more efficiently with only
	 * the line return this.children.add(child) because that may
	 * do the duplicate checking for you. Needs testing.
	 */
	public boolean addChild(Node child) {
		for(Node n : this.children) {
			if(n.equals(child))
				return false;
		}
		
		return this.children.add(child);
	}
	
	public boolean removeChild(Node child) {
		return this.children.remove(child);
	}

	// Accessor Methods
	public Node getParent() {
		return parent;
	}

	public void setParent(Node parent) {
		this.parent = parent;
	}

	public Collection<Node> getChildren() {
		return children;
	}

	public void setChildren(Collection<Node> children) {
		this.children = children;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public boolean isVisited() {
		return visited;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}
}
